<%@page import="com.netcracker.entity.Genre"%>
<%@page import="com.netcracker.entity.Author"%>
<%@page import="com.netcracker.entity.Book"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    List<Book> books = (List<Book>) request.getAttribute("books");
    List<Author> authors = (List<Author>) request.getAttribute("authors");
    List<Genre> genres = (List<Genre>) request.getAttribute("genres");
    String path = request.getContextPath();
%>
<article id="results">
    <%
        if (authors != null) {
    %>
    <section id= "authors">
        <header class="elem_bground">
            <h1>Найденные авторы</h1>
        </header>
        <%
            for (Author currentAuthor : authors) {
        %>
        <div class="element">
            <h2><%=currentAuthor.getFullName()%> </h2>
        </div>
        <%
                }
            }
        %>
        <%
            if (books != null) {
        %>
        <section id= "books">
            <header class="elem_bground">
                <h1>Найденные книги</h1>
            </header>
            <%
                for (Book currentBook : books) {
            %>
            <div class="element">
                <h2><a href="<%=path + "?action=findBook&type=byName&name=" + currentBook.getName()%>"> <%= currentBook.getName()%> </a> </h2>
                <p>Автор: 
                    <%
                        for (Author currentAuthor : currentBook.getAuthors()) {
                            out.print("<a href=\"" + path + "?action=findBook&type=byAuthor&author=" + currentAuthor.getFullName() + "\">" + currentAuthor.getFullName() + "</a> \n");
                        }
                    %>
                </p>
                <p>Жанр: 
                    <%
                        for (Genre currentGenre : currentBook.getGenres()) {
                            out.print("<a href=\"" + path + "?action=findBook&type=byGenre&genreId=" + currentGenre.getId() + "\"> " + currentGenre.getName() + "</a> \n");
                        }
                    %>
                </p>
            </div>
            <%
                    }
                }
            %>
        </section>


    </section>
</article><!--results-->
